﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;

using CE.Configuration;
using CE.Global;
using CE.User;
using CE.Image;
using CE.Mail;
using CE.CarInsurance;
using CE.Company;
using CE.Database;
using CE.CMI;


public partial class cmi_complete_cmi : MyLanguageBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["COMCMIID"] != null)
            {
                    CMI _cmi = new CMI();
                    CMIDB _cmidb = new CMIDB();
                    _cmi.CMIId = Convert.ToInt64(Session["COMCMIID"].ToString());
                    if (Request.Params["successcode"] != null && Request.Params["PayRef"] != null)
                    {
                        _cmi.Status = Request.Params["successcode"].ToString();
                        _cmi.TrackingCode = Request.Params["PayRef"].ToString();
                    }
                    else
                    {
                        _cmi.Status = "FAIL";
                    }
                    _cmidb.InsertUpdate(_cmi);
                string cmiid = Session["COMCMIID"].ToString();
                //Session["COMCMIID"] = null;
                FillIn(cmiid);
                SendProposalToAgent(cmiid);
                SendCMIToUser();
            }
        }
    }

    #region FillIn

    private void FillIn(string cmiid)
    {
        CMI _cmi = new CMI();
        CMIDB _cmidb = new CMIDB();
        _cmi = _cmidb.GetCMI(Convert.ToInt64(cmiid));

        hidCarType.Value = _cmi.CarType.ToString();
        hidCMIType.Value = _cmi.ServiceType.ToString();

        if (_cmi.ServiceType == '2')
        {
            divCarTaxDetail.Style.Add("display", "");
            chkTax.Checked = true;
        }
        else if (_cmi.ServiceType == '3')
        {
            divCarTaxDetail.Style.Add("display", "");
            divCMIDetail.Style.Add("display", "none");
            chkTax.Checked = true;
        }

        if (_cmi.CMIDate != null)
        {
            lblCTPLDate.Text = _cmi.CMIDate.Value.ToString("dd") + "/" + _cmi.CMIDate.Value.ToString("MM") + "/" + _cmi.CMIDate.Value.ToString("yyyy");
        }

        hidCarType.Value = _cmi.CarType.ToString();
        if (_cmi.RegistrationDate != null)
        {
            chkTax.Checked = true;
            lblRegistrationDate.Text = _cmi.RegistrationDate.Value.ToString("dd") + "/" + _cmi.RegistrationDate.Value.ToString("MM") + "/" + _cmi.RegistrationDate.Value.ToString("yyyy");

            if (_cmi.CarWeight.Trim() != "")
            {
                divCarWeight.Style.Add("display", "");
                lblCarWeight.Text = _cmi.CarWeight;
            }
        }

        if (_cmi.CTPLAmout > 0) lblSumCTPL.Text = _cmi.CTPLAmout.ToString();
        if (_cmi.CTPLDiscount > 0) lblSumDiscount.Text = _cmi.CTPLDiscount.ToString();
        if (_cmi.TaxRenewalAmount > 0)
        {
            lblSumTaxAndPanalty.Text = _cmi.TaxRenewalAmount.ToString();
            hidCalTaxAndPanalty.Value = _cmi.TaxRenewalAmount.ToString();
        }
        if (_cmi.ChargedAmount > 0)
        {
            lblSumCharged.Text = _cmi.ChargedAmount.ToString();
            hidSumCharged.Value = _cmi.ChargedAmount.ToString();
        }
        if (_cmi.EMS > 0)
        {
            lblSumEMS.Text = _cmi.EMS.ToString();
            hidSumEMS.Value = _cmi.EMS.ToString();
        }
        if (_cmi.CMITotal > 0)
        {
            lblTotal.Text = _cmi.CMITotal.ToString();
            hidTotal.Value = _cmi.CMITotal.ToString();
        }

        string _tempDesc = _cmi.CarModel + " " + _cmi.Body + " " + _cmi.CC + "cc " + _cmi.Door.ToString() + " doors";
        lblCarMakeModel.Text = _cmi.CarMake + " " + _tempDesc;
       
        lblChassisNo.Text = _cmi.ChassisNo;
        lblEngineNumber.Text = _cmi.EngineNumber;
        lblEngineSize.Text = _cmi.EngineSize;

        if (CultureInfo.CurrentCulture.Name != "th-TH")
        {
            lblManufactYear.Text = _cmi.ManufactYear.ToString();

            string[] colorTH = {"ขาว","เขียว","ชมพู","ดำ","แดง","ทอง","เทา","น้ำตาล","น้ำเงิน","บรอนซ์",
                                 "ฟ้า","ม่วง","ส้ม","เหลือง","บรอนซ์เงิน","บรอนซ์ทอง"};
            string[] colorEN = {"White","Green","Pink","Black","Red","Golden","Gray","Brown","Blue","Bronze",
                                 "Light blue","Purple","Orange","Yellow","Silver","Golden bronze"};

            for (int i = 0; i < colorTH.Length; i++)
            {
                if (_cmi.CarColor == colorTH[i])
                {
                    lblColor.Text = colorEN[i];
                    break;
                }
            }

        }
        else
        {
            lblManufactYear.Text = _cmi.ManufactYear.ToString() + " - พ.ศ. " + (_cmi.ManufactYear + 543).ToString();
            lblColor.Text = _cmi.CarColor;
        }

        lblName.Text = _cmi.Name;
        lblOwnerName.Text = _cmi.OwnerName;
        lblCarPlate.Text = _cmi.CarPlate + " " + _cmi.Province;
        lblAddress.Text = _cmi.Address;
        lblEmail.Text = _cmi.Email;
        lblMobileNo.Text = _cmi.Mobile;
        chkCopyAddress.Checked = _cmi.IsSameAddress;
        chkCopyAddress.Enabled = false;
        if (_cmi.IsSameAddress)
        {
            lblDeliveryAddress.Text = "";
            lblDeliveryName.Text = "";
        }
        else
        {
            divDelivery.Style.Add("display", "");
            lblDeliveryAddress.Text = _cmi.DeliveryAddress;
            lblDeliveryName.Text = _cmi.DeliveryName;
        }

        if (_cmi.DeliveryDate != null)
        {
            lblDeliveryDate.Text = _cmi.DeliveryDate.Value.ToString("dd") + "/" + _cmi.DeliveryDate.Value.ToString("MM") + "/" + _cmi.DeliveryDate.Value.ToString("yyyy");
        }

        lblTrackCode.Text = _cmi.TrackingCode;

        // PaymentType
        //if (_cmi.ProviderCompanyId > 0) lblProviderCompany.Text = "";
        //if (_cmi.ExpiryMonth.ToString().Trim() != "") lblExpiryMonth.Text = "";
    }
    #endregion

    #region Email
    private bool SendProposalToAgent(string CMIId)
    {
        Int64 _carId = Convert.ToInt64(Session[General.CMICarId].ToString());
        CE.User.Profile usrprofile = new Profile();
        ProfileDB usrprofiledb = new ProfileDB();

        usrprofile = usrprofiledb.GetProfile(Convert.ToInt64(Session[General.UserId].ToString()));

        string userfirstname = "";

        if (usrprofile != null)
        {
            userfirstname = usrprofile.FirstName;
        }

        string _refNo = "";
        CarDetailTH _cardetailth = new CarDetailTH();
        CarDetailTHDB _cardetailthdb = new CarDetailTHDB();
        CE.Database.MyDatabase _db = new CE.Database.MyDatabase();
        DataSet _dsInsurance = new DataSet();

        string _CarYear = "";
        string _CarMakeModel = "";
        string _CarType = "";
        string _CarPlate = "";
        string _Name = "";
        string _serviceType ="";

        Int64 _companyId = 0;

        CMI _cmi = new CMI();
        CMIDB _cmidb = new CMIDB();
        _cmi = _cmidb.GetCMI(Convert.ToInt64(Session[General.CMIId]));
        _companyId = _cmi.CTPLProviderCompanyId;

        _CarYear = _cmi.ManufactYear.ToString();
        _CarMakeModel = _cmi.MakeModelDesc;

        if(_cmi.ServiceType == '1')
            _serviceType = Resources.EmailMessage.CMISubject1.ToString();
        else if (_cmi.ServiceType == '2')
            _serviceType = Resources.EmailMessage.CMISubject2.ToString();
        else if (_cmi.ServiceType == '3')
            _serviceType = Resources.EmailMessage.CMISubject3.ToString();

        if (_cmi.CarType == '1')
            _CarType = GetGlobalResourceObject("CarInsurance", "VehicleType1").ToString();
        else if (_cmi.CarType == '2')
            _CarType = GetGlobalResourceObject("CarInsurance", "VehicleType2").ToString();
        else if (_cmi.CarType == '3')
            _CarType = GetGlobalResourceObject("CarInsurance", "VehicleType3").ToString();


        _CarPlate = _cmi.CarPlate.ToString();

        _Name = _cmi.Name;
        _refNo = _cmi.QuoteRefNo.ToString();


        bool _retVal = false;
        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");

        string _emailTo = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_TO"].ToString();
        string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_CC"].ToString();
        string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CI_ADM_BCC"].ToString();
        string _customername = Session[General.UserName].ToString();
        string _emailSubject = "";
        string _mailBody = "";
        string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Authority.ToString();
        string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LogoPath");
        string _providercompanyid = _cmi.CTPLProviderCompanyId.ToString();
        string _companyName = "";
        if (_providercompanyid == "11")
        {
            _companyName = "AZCP Insurance";
        }
        else if (_providercompanyid == "29")
        {
            _companyName = "LMG Insurance";
        }
        else if (_providercompanyid == "12")
        {
            _companyName = "MSIG Insurance";
        }
        else if (_providercompanyid == "16")
        {
            _companyName = "AXA Insurance";
        }
        else if (_providercompanyid == "31")
        {
            _companyName = "Chartis Insurance";
        }
        else if (_providercompanyid == "32")
        {
            _companyName = "Bangkok Insurance";
        }
        else if (_providercompanyid == "41")
        {
            _companyName = "Kurnia Insurance";
        }

        _emailSubject = "<Online> - " + Resources.ErrorMessage.PayMsgBody103 + " - " + _serviceType + "-" + _companyName;

        _mailBody = "<body class='email_body'>";
        _mailBody += "<style type='text/css'>";
        _mailBody += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 0.85em;}";
        _mailBody += "a {text-decoration:underline;color:#2c95cc;} ";
        _mailBody += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
        _mailBody += "#email_body {width:100%; text-align: left !important;} ";
        _mailBody += ".email_pad10px {padding:10px;} ";
        _mailBody += ".email_results td {width:33%;} ";
        _mailBody += "</style>";
        _mailBody += "<center> <br /><br />";

        _mailBody += "<table cellpadding='0' cellspacing='0' border='0' width='570'>";
        _mailBody += "<tr><td width='570'><table cellspacing='0' cellpadding='0' width='100%' border='0'>";
        if (Session[CE.Global.General.AgentId] != null && Session[CE.Global.General.AgentName] != null)
        {
            _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.ErrorMessage.PayMsgBody103 + " - " + Session[CE.Global.General.AgentName].ToString() + "</strong><br /><br />";
        }
        else
        {
            _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.ErrorMessage.PayMsgBody103 + "</strong><br /><br />";
        }
        _mailBody += Resources.Proposal.AgentMessage + "<br/><br/>";
        _mailBody += "<br/><strong>" + Resources.Proposal.OrderNo + " </strong>" + _cmi.OrderRefNo + "</td><td width='50%' align='right' valign='top'><img src='" + _currentDomainUrl + "/images/public/logo/logo_gluaygluay.png' width='130' height='99'/></td></tr>";
        _mailBody += "</table>";

        _mailBody += "<table cellspacing='0' cellpadding='2' width='570' border='0'>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.RefNo + ": " + _refNo + "</td><td valign='top'>" + Resources.Proposal.OrderDate + ": " + DateTime.Now.ToString("dd/MMM/yyyy") + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.NameLastname + ": " + _Name + "</td><td valign='top'>" + Resources.Proposal.LicensePlateNo + ": " + _CarPlate + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.MakeModel + ": " + _CarMakeModel + "</td><td valign='top'>" + Resources.Proposal.CarYear + ": " + _CarYear + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.CarInsurance.CTPLStartDate + ": " + _cmi.CMIDate + " </td><td valign='top'></td></tr>";
        _mailBody += "</table> <br /><br />";



        _mailBody += "<table cellpadding='5' cellspacing='0' border='0' width='100%' class='table_details'>";



        //if (dtResults.Rows.Count > 0)
        //{
        //logo
        string logourl = CE.Global.General.GetProviderCompanyLogo(_providercompanyid);

        _mailBody += "<tr>";
        _mailBody += "<td width='45%'></td>";
        _mailBody += "<td width='55%' align='center' style='background:#e0e0e0; border-bottom:white 1px dashed;'><img src='" + _currentDomainUrl + logourl + "' width='130' style='padding:3px;'/></td>";
        _mailBody += "</tr>";

        //cmi Session["CMICTPL"].ToString();
        //cmi discount Session["CMICTPLDISC"].ToString();
        //if (Session["CMITOTAL"] != null) lblTotal.Text = Session["CMITOTAL"].ToString();
        //if (Session["CMITOTAL"] != null) hidTotal.Value = Session["CMITOTAL"].ToString();


        _mailBody += "<tr>";
        _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Insurer + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5; color:white;'><strong>" + _companyName + "</ br>" + _CarType + "</strong></td>";
        _mailBody += "</tr>";



        string CMIPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.CTPLAmout.ToString()));
        if (CMIPrice == "0")
        {
            CMIPrice = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string CMIDiscount = String.Format("{0:#,0}", Convert.ToSingle(_cmi.CTPLDiscount.ToString()));
        if (CMIDiscount == "0")
        {
            CMIDiscount = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string TaxAndPanaltyPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.TaxRenewalAmount.ToString()));
        if (TaxAndPanaltyPrice == "0")
        {
            TaxAndPanaltyPrice = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string ChargedPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.ChargedAmount.ToString()));
        if (ChargedPrice == "0")
        {
            ChargedPrice = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string EMSPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.EMS.ToString()));
        if (EMSPrice == "0")
        {
            EMSPrice = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string TotalPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.CMITotal.ToString()));

        //CTPL"
        _mailBody += "<tr>";
        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.ResultPage.CTPL + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5' >" + CMIPrice + "</td>";
        _mailBody += "</tr>";

        //Discount
        _mailBody += "<tr>";
        _mailBody += "<td><strong>" + Resources.CarInsurance.Discount + "</strong></td>";
        _mailBody += "<td align='center' style='background:#c5c5c5' >" + CMIDiscount + "</td>";
        _mailBody += "</tr>";

        //TaxAndPanalty
        _mailBody += "<tr>";
        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsurance.TaxAndPanalty + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5' >" + TaxAndPanaltyPrice + "</td>";
        _mailBody += "</tr>";

        //Charged
        _mailBody += "<tr>";
        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsurance.Charged + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5' >" + ChargedPrice + "</td>";
        _mailBody += "</tr>";


        //EMS
        _mailBody += "<tr>";
        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsurance.EMS + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5' >" + EMSPrice + "</td>";
        _mailBody += "</tr>";


        //premium
        _mailBody += "<tr>";
        _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.TotalVMI + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

        _mailBody += "<br/><strong>" + TotalPrice + "</strong>";



        _mailBody += "</td>";
        _mailBody += "</tr>";


        //}

        _mailBody += "</table>";
        _mailBody += "</td></tr>";
        _mailBody += "<tr><td id='email_footer'>";
        _mailBody += "</td></tr></table>";
        _mailBody += "</center></body>";

        if (MyMailManager.SendSelectedCARMessageToAgent(_emailTo, _emailCC, _emailBCC, _emailSubject + " (Ref No : " + _refNo + ") ", _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    private bool SendCMIToUser()
    {
        Int64 _carId = Convert.ToInt64(Session[General.CMICarId].ToString());
        CE.User.Profile usrprofile = new Profile();
        ProfileDB usrprofiledb = new ProfileDB();

        usrprofile = usrprofiledb.GetProfile(Convert.ToInt64(Session[General.UserId].ToString()));

        string userfirstname = "";

        if (usrprofile != null)
        {
            userfirstname = usrprofile.FirstName;
        }

        string _refNo = "";
        CarDetailTH _cardetailth = new CarDetailTH();
        CarDetailTHDB _cardetailthdb = new CarDetailTHDB();
        CE.Database.MyDatabase _db = new CE.Database.MyDatabase();
        DataSet _dsInsurance = new DataSet();

        string _CarYear = "";
        string _CarMakeModel = "";
        string _CarType = "";
        string _CarPlate = "";
        string _Name = "";
        string _serviceType = "";

        Int64 _companyId = 0;

        CMI _cmi = new CMI();
        CMIDB _cmidb = new CMIDB();
        _cmi = _cmidb.GetCMI(Convert.ToInt64(Session[General.CMIId]));
        _companyId = _cmi.CTPLProviderCompanyId;

        _CarYear = _cmi.ManufactYear.ToString();
        _CarMakeModel = _cmi.MakeModelDesc;

        if (_cmi.ServiceType == '1')
            _serviceType = Resources.EmailMessage.CMISubject1.ToString();
        else if (_cmi.ServiceType == '2')
            _serviceType = Resources.EmailMessage.CMISubject2.ToString();
        else if (_cmi.ServiceType == '3')
            _serviceType = Resources.EmailMessage.CMISubject3.ToString();

        if (_cmi.CarType == '1')
            _CarType = GetGlobalResourceObject("CarInsurance", "VehicleType1").ToString();
        else if (_cmi.CarType == '2')
            _CarType = GetGlobalResourceObject("CarInsurance", "VehicleType2").ToString();
        else if (_cmi.CarType == '3')
            _CarType = GetGlobalResourceObject("CarInsurance", "VehicleType3").ToString();


        _CarPlate = _cmi.CarPlate.ToString();

        _Name = _cmi.Name;
        _refNo = _cmi.QuoteRefNo.ToString();


        bool _retVal = false;
        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");

        string _emailTo = _cmi.Email;
        string _customername = Session[General.UserName].ToString();
        string _emailSubject = "";
        string _mailBody = "";
        string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Authority.ToString();
        string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LogoPath");
        string _providercompanyid = _cmi.CTPLProviderCompanyId.ToString();
        string _companyName = "";
        if (_providercompanyid == "11")
        {
            _companyName = "AZCP Insurance";
        }
        else if (_providercompanyid == "29")
        {
            _companyName = "LMG Insurance";
        }
        else if (_providercompanyid == "12")
        {
            _companyName = "MSIG Insurance";
        }
        else if (_providercompanyid == "16")
        {
            _companyName = "AXA Insurance";
        }
        else if (_providercompanyid == "31")
        {
            _companyName = "Chartis Insurance";
        }
        else if (_providercompanyid == "32")
        {
            _companyName = "Bangkok Insurance";
        }
        else if (_providercompanyid == "41")
        {
            _companyName = "Kurnia Insurance";
        }

        _emailSubject = "<Online> - " + Resources.ErrorMessage.PayMsgBody103 + " - " + _serviceType + "-" + _companyName;

        _mailBody = "<body class='email_body'>";
        _mailBody += "<style type='text/css'>";
        _mailBody += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 0.85em;}";
        _mailBody += "a {text-decoration:underline;color:#2c95cc;} ";
        _mailBody += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
        _mailBody += "#email_body {width:100%; text-align: left !important;} ";
        _mailBody += ".email_pad10px {padding:10px;} ";
        _mailBody += ".email_results td {width:33%;} ";
        _mailBody += "</style>";
        _mailBody += "<center> <br /><br />";

        _mailBody += "<table cellpadding='0' cellspacing='0' border='0' width='570'>";
        _mailBody += "<tr><td width='570'><table cellspacing='0' cellpadding='0' width='100%' border='0'>";
        if (Session[CE.Global.General.AgentId] != null && Session[CE.Global.General.AgentName] != null)
        {
            _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.ErrorMessage.PayMsgBody103 + " - " + Session[CE.Global.General.AgentName].ToString() + "</strong><br /><br />";
        }
        else
        {
            _mailBody += "<tr><td width='50%' valign='top'><strong>" + Resources.ErrorMessage.PayMsgBody103 + "</strong><br /><br />";
        }
        _mailBody += Resources.Proposal.AgentMessage + "<br/><br/>";
        _mailBody += "<br/><strong>" + Resources.Proposal.OrderNo + " </strong>" + _cmi.OrderRefNo + "</td><td width='50%' align='right' valign='top'><img src='" + _currentDomainUrl + "/images/public/logo/logo_gluaygluay.png' width='130' height='99'/></td></tr>";
        _mailBody += "</table>";

        _mailBody += "<table cellspacing='0' cellpadding='2' width='570' border='0'>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.RefNo + ": " + _refNo + "</td><td valign='top'>" + Resources.Proposal.OrderDate + ": " + DateTime.Now.ToString("dd/MMM/yyyy") + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.NameLastname + ": " + _Name + "</td><td valign='top'>" + Resources.Proposal.LicensePlateNo + ": " + _CarPlate + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.Proposal.MakeModel + ": " + _CarMakeModel + "</td><td valign='top'>" + Resources.Proposal.CarYear + ": " + _CarYear + "</td></tr>";
        _mailBody += "<tr><td valign='top'>" + Resources.CarInsurance.CTPLStartDate + ": " + _cmi.CMIDate + " </td><td valign='top'></td></tr>";
        _mailBody += "</table> <br /><br />";



        _mailBody += "<table cellpadding='5' cellspacing='0' border='0' width='100%' class='table_details'>";



        //if (dtResults.Rows.Count > 0)
        //{
        //logo
        string logourl = CE.Global.General.GetProviderCompanyLogo(_providercompanyid);

        _mailBody += "<tr>";
        _mailBody += "<td width='45%'></td>";
        _mailBody += "<td width='55%' align='center' style='background:#e0e0e0; border-bottom:white 1px dashed;'><img src='" + _currentDomainUrl + logourl + "' width='130' style='padding:3px;'/></td>";
        _mailBody += "</tr>";

        //cmi Session["CMICTPL"].ToString();
        //cmi discount Session["CMICTPLDISC"].ToString();
        //if (Session["CMITOTAL"] != null) lblTotal.Text = Session["CMITOTAL"].ToString();
        //if (Session["CMITOTAL"] != null) hidTotal.Value = Session["CMITOTAL"].ToString();


        _mailBody += "<tr>";
        _mailBody += "<td><strong>" + Resources.CarInsuranceResultPage.Insurer + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5; color:white;'><strong>" + _companyName + "</ br>" + _CarType + "</strong></td>";
        _mailBody += "</tr>";



        string CMIPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.CTPLAmout.ToString()));
        if (CMIPrice == "0")
        {
            CMIPrice = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string CMIDiscount = String.Format("{0:#,0}", Convert.ToSingle(_cmi.CTPLDiscount.ToString()));
        if (CMIDiscount == "0")
        {
            CMIDiscount = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string TaxAndPanaltyPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.TaxRenewalAmount.ToString()));
        if (TaxAndPanaltyPrice == "0")
        {
            TaxAndPanaltyPrice = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string ChargedPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.ChargedAmount.ToString()));
        if (ChargedPrice == "0")
        {
            ChargedPrice = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string EMSPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.EMS.ToString()));
        if (EMSPrice == "0")
        {
            EMSPrice = "<img src='" + _currentDomainUrl + "/images/icon/X.png' width='16' alt='NA' />";
        }
        string TotalPrice = String.Format("{0:#,0}", Convert.ToSingle(_cmi.CMITotal.ToString()));

        //CTPL"
        _mailBody += "<tr>";
        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.ResultPage.CTPL + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5' >" + CMIPrice + "</td>";
        _mailBody += "</tr>";

        //Discount
        _mailBody += "<tr>";
        _mailBody += "<td><strong>" + Resources.CarInsurance.Discount + "</strong></td>";
        _mailBody += "<td align='center' style='background:#c5c5c5' >" + CMIDiscount + "</td>";
        _mailBody += "</tr>";

        //TaxAndPanalty
        _mailBody += "<tr>";
        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsurance.TaxAndPanalty + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5' >" + TaxAndPanaltyPrice + "</td>";
        _mailBody += "</tr>";

        //Charged
        _mailBody += "<tr>";
        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsurance.Charged + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5' >" + ChargedPrice + "</td>";
        _mailBody += "</tr>";


        //EMS
        _mailBody += "<tr>";
        _mailBody += "<td style='border-bottom:1px solid #ccc;'><strong>" + Resources.CarInsurance.EMS + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5' >" + EMSPrice + "</td>";
        _mailBody += "</tr>";


        //premium
        _mailBody += "<tr>";
        _mailBody += "<td align='left' ><strong>" + Resources.CarInsuranceResultPage.TotalVMI + "</strong></td>";
        _mailBody += "<td align='center' style='background:#d5d5d5; color:F00; font-size:20px;'>";

        _mailBody += "<br/><strong>" + TotalPrice + "</strong>";



        _mailBody += "</td>";
        _mailBody += "</tr>";


        //}

        _mailBody += "</table>";
        _mailBody += "</td></tr>";
        _mailBody += "<tr><td id='email_footer'>";
        _mailBody += "</td></tr></table>";
        _mailBody += "</center></body>";

        if (MyMailManager.SendSelectedCARMessage(_emailTo, _emailSubject, _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    #endregion
}
